package com.xliu.csopenproject.pim_server;

public class Utils {
    private Utils() {
    }

    // 十进制度(Decimal Degrees，DD) 转度分秒(Degrees Minute Second,DMS)
    public static String dd2dms(double dd) {
        int degree = (int)Math.floor(dd);
        double decimal = (dd - degree) * 60;
        int minute = (int)Math.floor(decimal);

        decimal = (decimal - minute) * 60;
        int seconds = (int)Math.round(decimal);

        return String.format("%d° %d' %d\"", degree, minute, seconds);

    }

    public static double dms2dd(String dms) {
        String[] parts = dms.split("°");
        double value = Double.parseDouble(parts[0]);
        parts = parts[1].split("'");
        value += Double.parseDouble(parts[0]) / 60;
        parts = parts[1].split("\"");
        value += Double.parseDouble(parts[0]) / 3600;

        return value;
    }
}
